package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.dto.PetQueryDto;
import com.example.pojo.entity.Pet;
import com.example.pojo.vo.PetQueryVo;
import com.example.service.PetService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 宠物 controller 层
 */
@RestController
@RequestMapping("/pet")
public class PetController {

    @Resource
    private PetService petService;

    @PostMapping("/add")
    public Result add(@RequestBody Pet pet) {
        this.petService.add(pet);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            PetQueryDto dto
    ) {
        PageResult<PetQueryVo> pageResult = this.petService.pageQuery(pageNum, pageSize, dto);
        return Result.success(pageResult);
    }

    @GetMapping("/query")
    public Result queryById(@RequestParam Integer id) {
        PetQueryVo pet = this.petService.queryById(id);
        return Result.success(pet);
    }

    @GetMapping("/query/all")
    public Result queryAll(PetQueryDto dto) {
        List<PetQueryVo> petList = this.petService.queryAll(dto);
        return Result.success(petList);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Pet pet) {
        this.petService.update(pet);
        return Result.success();
    }


    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        this.petService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.petService.deleteBatch(ids);
        return Result.success();
    }
}
